<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="login-form">
			<view class="login-form__input">
				<uv-input v-model="userForm.username" placeholder="用户名" type="text" shape="circle" border="none" :customStyle="{padding: '8px 18px', backgroundColor: '#ffffff'}"></uv-input>
			</view>
			<view class="login-form__input">
				<uv-input v-model="userForm.password" placeholder="密码" type="password" shape="circle" border="none" :customStyle="{padding: '8px 18px', backgroundColor: '#ffffff'}"></uv-input>
			</view>
		</view>
		<view class="login-submit">
			<uv-button type="primary" text="登 录" :customStyle="{padding: '8px 18px', borderRadius: '25px'}" @click="submit()"></uv-button>
		</view>
		<view class="login-third">
			
		</view>
		<view class="login-footer">
			<!-- <view class="login-footer__text">找回密码</view>
			<uv-line direction="col" :length="10" margin="10px" color="#5e5e5e"></uv-line> -->
			<view class="login-footer__text" @click="register()">注册账号</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { reactive } from 'vue';
	import { useUserStore, useAppStore } from '@/store';
	import { LoginData } from '@/api/login';
	import {pages} from '@/utils/page-url';
	
	// 用户store
	const userStore = useUserStore();
	// 应用store
	const appStore = useAppStore();
	
	const userForm: LoginData = reactive({
		username: 'admin',
		password: '123456',
    types: ['user']
	});
	
	
	const submit = async () => {
		const params = JSON.parse(JSON.stringify(userForm));
		await userStore.login(params);
		if (appStore.loginAuth) {
			// @ts-ignore
			uni.$uv.route({
				type: 'reLaunch',
				url: pages.home
			})
		} else {
			// @ts-ignore
			uni.$uv.route({
				type: 'back'
			})
		}
	}
	
	const register = () => {
		// @ts-ignore
		uni.$uv.route({
			type: 'to',
			url: pages.register
		});
		
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	
	.logo {
		height: 150rpx;
		width: 150rpx;
		margin-top: 50rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}
	
	.login-form {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100%;
		
		&__input {
			margin: 20rpx 0;
			width: 70%;
			filter: drop-shadow(1px 2px 8px #e3e3e3);
		}
	}
	
	.login-submit {
		width: 70%;
		margin-top: 50rpx;
		filter: drop-shadow(1px 2px 8px #e3e3e3);
	}
	
	.login-footer {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		margin-top: 50px;
		
		&__text {
			font-size: 12px;
			color: $uv-content-color;
		}
	}
</style>

<style lang="scss" scoped>
</style>